const app = getApp();
const util = require('../../../utils/util.js');
const lbbService = require('../../../pages/service/service.js');
const lbbTaskService = require('../service/task-service.js');
const operateMethod =require('../service/operatef.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isArriveScene: 1,
        mechanismUpdate: 1,
        basicInformation: {},
        hosLevelList: [],
        formatter(type, value) {
            if (type === 'year') {
                return `${value}年`;
            }
            if (type === 'month') {
                return `${value}月`;
            }
            return value;
        },
        hasFriendLyInfo: 0,
        hasFriendlyAgentList: [{
            text: '有',
            value: 1
        }, {
            text: '无',
            value: 0
        }],
        friendlyCollect: 0,
        friendlyCollectList: [{
            text: '采集到',
            value: 1
        }, {
            text: '未采集到',
            value: 0
        }],
        friendlyInfo: [{
            deviceList: [{}],
            contactList: [],
            hasFriendlyAgent: 0
        }],
        contactObj: {},
        onBeforeClose(action, done) {
            if (action == 'confirm') {
                return false
            } else {
                return true
            }
        },
        deptCollect: 0,
        departmentInfo: [{
            contactList: []
        }],
        companyInfo:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this
        that.setData({
            taskId: options.taskId,
            hospitalId: options.hospitalId,
            taskType:options.taskType,
            operationlist : options.operationlist?JSON.parse(options.operationlist):[],
            operationTypeCode:options.operationTypeCode,
            activeKey:options.activeKey
        })
        that.getDetailById()
        that.getProjectList('hospital_level')
        that.getProjectList('hospital_nature')
        that.getProjectList('hospital_type')
        that.getProjectList('friendly_business')
        that.getProjectList('friendly_deviceType')
        that.getProjectList('contact_information')
        that.getProjectList('Hospital_department')
        that.getCollectHospital()
    },
    //获取任务详情
    getDetailById() {
        let that = this
        let InterfaceItem=that.data.taskType=='long'?lbbTaskService.getLongDetailById:lbbTaskService.getDetailById
        InterfaceItem({
            taskId: that.data.taskId
        }, function (res) {
            if (res.data) {
                that.setData({
                    taskProjectText: res.data.taskProjectText,
                    taskClassificationName: res.data.taskClassificationName,
                    hospitalName: res.data.hospitalName,
                    taskDesc: res.data.taskDesc,
                    taskImages: res.data.taskImages ? res.data.taskImages.split(',') : [],
                    isUrgent: res.data.isUrgent
                })
            }
        })
    },
    //获取数据字典值
    getProjectList(code) {
        let that = this
        lbbTaskService.getDictByCode({
            code: code
        }, function (res) {
            if (code == 'hospital_level') {
                // that.data.basicInformation.hosLevel = res.data[0]?.value
                res.data.unshift({
                    text: '请选择',
                    value: ''
                })
                that.setData({
                    hosLevelList: res.data,
                    basicInformation: that.data.basicInformation
                })
            } else if (code == 'hospital_nature') {
                // that.data.basicInformation.optType = res.data[0]?.value
                res.data.unshift({
                    text: '请选择',
                    value: ''
                })
                that.setData({
                    optTypeList: res.data,
                    basicInformation: that.data.basicInformation
                })
            } else if (code == 'hospital_type') {
                // that.data.basicInformation.hosType = res.data[0]?.value
                res.data.unshift({
                    text: '请选择',
                    value: ''
                })
                that.setData({
                    hosTypeList: res.data,
                    basicInformation: that.data.basicInformation
                })
            } else if (code == 'friendly_business') {
                that.setData({
                    friendlyBusList: res.data
                })
            } else if (code == 'friendly_deviceType') {
                res.data.unshift({
                    text: '请选择',
                    value: ''
                })
                that.setData({
                    deviceNameList: res.data
                })
            } else if (code == 'contact_information') {
                that.setData({
                    contactTypeList: res.data
                })
            } else if (code == 'Hospital_department') {
                res.data.unshift({
                    text: '请选择',
                    value: ''
                })
                that.setData({
                    classNameList: res.data
                })
            }
        })
    },
    //医院信息回显
    getCollectHospital(){
        let that=this
        lbbTaskService.getCollectHospital({taskId:this.data.taskId,mechanismId:this.data.hospitalId},function(res) {
            //处理公司信息
            res.data.companyInfo.forEach(item=>{
                item.classList.forEach(itm=>{
                    itm.text=itm.label
                })
                item.companyList.forEach(itm=>{
                    if(!item.isCollect){
                        itm.contactList=[]
                    }
                })
                item.classList.unshift({
                    text: '请选择',
                    value: ''
                })
            })
            //处理基础信息
            if(!res.data.mechanismUpdate){
                that.data.basicInformation={}
            }else{
                that.data.basicInformation={hosSecondName:res.data.hosSecondName,hosLevel:res.data.hosLevel,optType:res.data.optType,hosType:res.data.hosType,departmentNum:res.data.departmentNum,outpatientNum:res.data.outpatientNum,berthNum:res.data.berthNum,area:res.data.area,employeeNum:res.data.employeeNum,establishmentTime:res.data.establishmentTime?res.data.establishmentTime.substring(0,10):'',concatTel:res.data.concatTel,postalCode:res.data.postalCode,deliveryAddress:res.data.deliveryAddress,unifiedSocialCode:res.data.unifiedSocialCode,webUrl:res.data.webUrl}
            }
            //处理部门信息
            if(!res.data.deptCollect){
               that.data.departmentInfo= [{
                    contactList: []
                }]
            }else{
                res.data.departmentInfo.forEach(item=>{
                    item.images=item.images?item.images.split(','):''
                    item.remark=item.remark?item.remark:''
                    item.contactList.forEach(itm=>{
                        itm.contactTypeText=that.data.contactTypeList.find(itemt=>itemt.value==itm.contactType).text
                    })
                })
                that.data.departmentInfo=res.data.departmentInfo
            }
            //处理友商信息
            if(res.data.hasFriendLyInfo&&res.data.friendlyCollect){
                res.data.friendlyInfo.forEach(item=>{
                    item.images=item.images?item.images.split(','):''
                    item.remark=item.remark?item.remark:''
                    item.friendlyBusinessText=that.data.friendlyBusList.find(itm=>itm.value==item.friendlyBusiness).text
                    item.contactList?.forEach(itm=>{
                        itm.contactTypeText=that.data.contactTypeList.find(itemt=>itemt.value==itm.contactType).text
                    })
                })
                that.data.friendlyInfo=res.data.friendlyInfo
            }else{
                that.data.friendlyInfo=[{
                    deviceList: [{}],
                    contactList: [],
                    hasFriendlyAgent: 0
                }]   
            }
            that.setData({
                companyInfo:res.data.companyInfo,
                basicInformation:that.data.basicInformation,
                departmentInfo:that.data.departmentInfo,
                friendlyInfo:that.data.friendlyInfo,
                isArriveScene:res.data.isArriveScene,
                mechanismUpdate:res.data.mechanismUpdate,
                friendlyCollect:res.data.friendlyCollect,
                deptCollect:res.data.deptCollect,
                hasFriendLyInfo:res.data.hasFriendLyInfo,
            })
            console.log(789,that.data.friendlyInfo)
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
    //是否到现场回调
    onChangeSceneRadio(e) {
        this.setData({
            isArriveScene: e.detail
        })
    },
    //有无更新回调
    onChangeUpdateRadio(e) {
        this.setData({
            mechanismUpdate: e.detail
        })
    },
    //医院别称
    onChangeHosSecondName(e) {
        this.data.basicInformation.hosSecondName = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //科室数回调
    onChangedepartment(e) {
        this.data.basicInformation.departmentNum = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //门诊量
    onChangeOutpatient(e) {
        this.data.basicInformation.outpatientNum = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //床位数
    onChangeBerth(e) {
        this.data.basicInformation.berthNum = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
        console.log(55, this.data.basicInformation)
    },
    //面积
    onChangeArea(e) {
        this.data.basicInformation.area = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //在职人数
    onChangeEmployee(e) {
        this.data.basicInformation.employeeNum = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //医院等级
    onChangeHosLevel(e) {
        this.data.basicInformation.hosLevel = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //医院性质
    onChangeOptType(e) {
        this.data.basicInformation.optType = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //医院类型
    onChangeHosType(e) {
        this.data.basicInformation.hosType = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //联系电话
    onChangeConcatTel(e){
        this.data.basicInformation.concatTel = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //邮政编码
    onChangePostalCode(e){
        this.data.basicInformation.postalCode = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //官网
    onChangeWebUrl(e){
        this.data.basicInformation.webUrl = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        })
    },
    //投放地址
    onChangeAddress(e){
        this.data.basicInformation.deliveryAddress = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        }) 
    },
    //社会信用代码
    onChangeSocialCode(e){
        this.data.basicInformation.unifiedSocialCode = e.detail
        this.setData({
            basicInformation: this.data.basicInformation
        }) 
    },
    //打开成立时间弹窗
    onBindEstabliTime() {
        this.setData({
            showEstabliTime: true,
            timeType: 'establish'
        })
    },
    //遮罩层关闭
    onCloseEstabliTime() {
        this.setData({
            showEstabliTime: false
        })
    },
    //取消
    cancelEstabliDate() {
        this.setData({
            showEstabliTime: false
        })
    },
    //确定时间
    okEstabliDate(e) {
        let reg = /\//g;
        let date = util.formatTime(new Date(e.detail)).substr(0, 10).replace(reg, '-')
        if (this.data.timeType == 'establish') {
            this.data.basicInformation.establishmentTime = date
            this.setData({
                basicInformation: this.data.basicInformation,
                showEstabliTime: false
            })
        } else if (this.data.timeType == 'delivery') {
            this.data.friendlyInfo[this.data.FriendlyIndex].deliveryEndDate = date
            this.setData({
                friendlyInfo: this.data.friendlyInfo,
                showEstabliTime: false
            })
        }

    },
    //友商信息有无
    onChangehasFriendlyAgent(e) {
        this.setData({
            hasFriendLyInfo: e.detail
        })
    },
    //友商信息是否采集到
    onChangeFriendlyCollect(e) {
        this.setData({
            friendlyCollect: e.detail
        })
    },
    //打开友商公司弹出层
    onBindFriendlyBus(e) {
        this.setData({
            friendlyBusIfShow: true,
            FriendlyIndex: e.currentTarget.dataset.index
        })
    },
    //确定选择友商的回调
    okFriendlyBus(e) {
        this.data.friendlyInfo[this.data.FriendlyIndex].friendlyBusiness = e.detail.id
        this.data.friendlyInfo[this.data.FriendlyIndex].friendlyBusinessText = e.detail.name
        this.setData({
            friendlyInfo: this.data.friendlyInfo,
            friendlyBusIfShow: false
        })
    },
    //选择设备
    onChangeDeviceName(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].deviceList[e.currentTarget.dataset.devindex].deviceName = e.detail
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //数量
    changeCount(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].deviceList[e.currentTarget.dataset.devindex].deviceCount = e.detail.value
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
        console.log(this.data.friendlyInfo)
    },
    //添加设备
    addDevice(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].deviceList.push({})
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //删除设备
    delDevice(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].deviceList.splice(e.currentTarget.dataset.devindex, 1)
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //投放到期时间
    onBindEndDate(e) {
        this.setData({
            showEstabliTime: true,
            FriendlyIndex: e.currentTarget.dataset.index,
            timeType: 'delivery'
        })
    },
    //友商代理商有无
    onChangeHasRadio(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].hasFriendlyAgent = e.detail
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //代理商名称
    onChangeAgentName(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].friendlyAgentName = e.detail
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //新增联系人
    addContacts(e) {
        this.setData({
            showContacts: true,
            listIndex: e.currentTarget.dataset.index,
            contactsType: 'Friendlyer'
        })
    },
    //联系人姓名回调
    onChangeName(e) {
        this.data.contactObj.name = e.detail
        this.setData({
            contactObj: this.data.contactObj
        })
    },
    //打开联系方式列表
    onBindcontactType(e) {
        this.setData({
            contactTypeIfShow: true
        })
    },
    //选择联系方式
    okContactType(e) {
        this.data.contactObj.contactTypeText = e.detail.name
        this.data.contactObj.contactType = e.detail.id
        this.setData({
            contactTypeIfShow: false,
            contactObj: this.data.contactObj
        })
    },
    //联系号码回调
    onChangecontactWay(e) {
        this.data.contactObj.contactWay = e.detail
        this.setData({
            contactObj: this.data.contactObj
        })
    },
    //联系人职务
    onChangeposition(e) {
        this.data.contactObj.position = e.detail
        this.setData({
            contactObj: this.data.contactObj
        })
    },
    //确定新增联系人
    onConfirmContacts() {
        if (this.data.contactObj.name && this.data.contactObj.contactType && this.data.contactObj.contactWay && this.data.contactObj.position) {
            if (this.data.contactsType == 'Friendlyer') {
                this.data.friendlyInfo[this.data.listIndex].contactList.push(this.data.contactObj)
                this.setData({
                    showContacts: false,
                    friendlyInfo: this.data.friendlyInfo,
                    contactObj: {}
                })
            } else if (this.data.contactsType == 'department') {
                this.data.departmentInfo[this.data.departmentIndex].contactList.push(this.data.contactObj)
                this.setData({
                    showContacts: false,
                    departmentInfo: this.data.departmentInfo,
                    contactObj: {}
                })
            }else if(this.data.contactsType=='companyType'){
                this.data.companyInfo[this.data.companyIndex].companyList[this.data.companylyIndex].contactList.push(this.data.contactObj)
                this.setData({
                    showContacts: false,
                    companyInfo: this.data.companyInfo,
                    contactObj: {}
                })
            }

            console.log(33, this.data.friendlyInfo)
        } else {
            this.openPrompt()
        }
    },
    //关闭联系人弹框
    onCloseContacts() {
        this.setData({
            contactObj: {}
        })
    },
    //删除友商联系人
    delContacterBox(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].contactList.splice(e.currentTarget.dataset.indext, 1)
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //友商备注
    changeFindRemark(e) {
        this.data.friendlyInfo[e.currentTarget.dataset.index].remark = e.detail.value
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    setFindImgArr(e) {
        let that = this
        let imgArray = e.detail;
        let newUpLoadImg = []
        let oldUpLoadImg = []
        imgArray.forEach(item => {
            if (item.indexOf('http://tmp/') != -1||item.indexOf('wxfile://tmp')!=-1) {
                newUpLoadImg.push(item)
            } else {
                oldUpLoadImg.push(item)
            }
        })
        wx.showLoading({
            title: '正在上传图片',
            mask: true
        })
        util.newUpLoadImg(app.globalData.header, newUpLoadImg, 0, [], function (imgIdArray) {
            console.log('item================>', imgIdArray)
            wx.hideLoading()
            oldUpLoadImg.push(...imgIdArray)
            that.data.friendlyInfo[e.currentTarget.dataset.index].images = oldUpLoadImg
        });
    },
    //删除友商
    delTask(e) {
        this.data.friendlyInfo.splice(e.currentTarget.dataset.index, 1)
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //添加友商
    addFriendlyInfo() {
        this.data.friendlyInfo.push({
            deviceList: [{}],
            contactList: [],
            hasFriendlyAgent: 0
        })
        this.setData({
            friendlyInfo: this.data.friendlyInfo
        })
    },
    //是否采集到医院部门信息
    onChangeDeptCollect(e) {
        this.setData({
            deptCollect: e.detail
        })
    },
    //联系人部门
    onChangeClassName(e) {
        console.log(e)
        this.data.departmentInfo[e.currentTarget.dataset.index].name = e.detail
        this.setData({
            departmentInfo: this.data.departmentInfo,
            departmentIndex: e.currentTarget.dataset.index
        })
    },
    //打开新增部门联系人
    addDepartmentContacts(e) {
        this.setData({
            showContacts: true,
            departmentIndex: e.currentTarget.dataset.index,
            contactsType: 'department'
        })
    },
    //删除部门信息联系人
    delDepartmentContacter(e){
        this.data.departmentInfo[e.currentTarget.dataset.index].contactList.splice(e.currentTarget.dataset.indext, 1)
        this.setData({
            departmentInfo: this.data.departmentInfo
        })
    },
    //医院部门信息备注
    changeDepartmentRemark(e){
        this.data.departmentInfo[e.currentTarget.dataset.index].remark = e.detail.value
        this.setData({
            departmentInfo: this.data.departmentInfo
        })
    },
    //医院部门信息图片
    setDepartmentImgArr(e){
        let that = this
        let imgArray = e.detail;
        let newUpLoadImg = []
        let oldUpLoadImg = []
        imgArray.forEach(item => {
            if (item.indexOf('http://tmp/') != -1||item.indexOf('wxfile://tmp')!=-1) {
                newUpLoadImg.push(item)
            } else {
                oldUpLoadImg.push(item)
            }
        })
        wx.showLoading({
            title: '正在上传图片',
            mask: true
        })
        util.newUpLoadImg(app.globalData.header, newUpLoadImg, 0, [], function (imgIdArray) {
            console.log('item================>', imgIdArray)
            wx.hideLoading()
            oldUpLoadImg.push(...imgIdArray)
            that.data.departmentInfo[e.currentTarget.dataset.index].images = oldUpLoadImg
        });
    },
    //添加部门
    addDepartment(){
       this.data.departmentInfo.push({contactList:[]})
       this.setData({
        departmentInfo:this.data.departmentInfo
       })
    },
    //删除部门
    delDepartmentTask(e){
        this.data.departmentInfo.splice(e.currentTarget.dataset.index,1)
        this.setData({
            departmentInfo:this.data.departmentInfo
           })
    },
    //公司信息是否采集到
    onChangeCollect(e){
        this.data.companyInfo[e.currentTarget.dataset.index].isCollect=e.detail
        this.setData({
            companyInfo:this.data.companyInfo
        })
    },
    //公司类型回调
    onChangeCompanyType(e){
      this.data.companyInfo[e.currentTarget.dataset.index].companyList[e.currentTarget.dataset.companyindex].companyType=e.detail  
      this.setData({
        companyInfo:this.data.companyInfo
    })
    },
    //公司名称回调
    onChangeCompanyName(e){
        this.data.companyInfo[e.currentTarget.dataset.index].companyList[e.currentTarget.dataset.companyindex].companyName=e.detail  
        this.setData({
          companyInfo:this.data.companyInfo
      })
    },
    //打开联系人
    addCompanyContacts(e){
        this.setData({
            showContacts: true,
            companyIndex: e.currentTarget.dataset.index,
            companylyIndex:e.currentTarget.dataset.companyindex,
            contactsType: 'companyType'
        })
    },
    //删除联系人
    delCompanyContacter(e){
        this.data.companyInfo[e.currentTarget.dataset.index].companyList[e.currentTarget.dataset.companyindex].contactList.splice(e.currentTarget.dataset.indext,1)
        this.setData({
            companyInfo:this.data.companyInfo
        })
    },
    //公司信息备注
    changeCompanyRemark(e){
        this.data.companyInfo[e.currentTarget.dataset.index].companyList[e.currentTarget.dataset.companyindex].remark=e.detail.value
        this.setData({
            companyInfo:this.data.companyInfo
        })
    },
    //公司信息图片
    setCompanyImgArr(e){
        let that = this
        let imgArray = e.detail;
        let newUpLoadImg = []
        let oldUpLoadImg = []
        imgArray.forEach(item => {
            if (item.indexOf('http://tmp/') != -1||item.indexOf('wxfile://tmp')!=-1) {
                newUpLoadImg.push(item)
            } else {
                oldUpLoadImg.push(item)
            }
        })
        wx.showLoading({
            title: '正在上传图片',
            mask: true
        })
        util.newUpLoadImg(app.globalData.header, newUpLoadImg, 0, [], function (imgIdArray) {
            console.log('item================>', imgIdArray)
            wx.hideLoading()
            oldUpLoadImg.push(...imgIdArray)
            that.data.companyInfo[e.currentTarget.dataset.index].companyList[e.currentTarget.dataset.companyindex].images = oldUpLoadImg
        });
    },
    //添加公司
    addCompanyInfo(e){
        this.data.companyInfo[e.currentTarget.dataset.index].companyList.push({contactList:[]})
        this.setData({
            companyInfo:this.data.companyInfo
        })
    },
    //删除公司
    delCompanyTask(e){
        this.data.companyInfo[e.currentTarget.dataset.index].companyList.splice(e.currentTarget.dataset.companyindex,1)
        this.setData({
            companyInfo:this.data.companyInfo
        })
    },
    //提交
    btnSubmit(){
       let that=this
       //基础信息校验
       let baseCheckList=[] 
        if(!that.data.mechanismUpdate){
            that.data.basicInformation={}
        }else{
            if(that.data.basicInformation.hosSecondName){
                baseCheckList.push(1)
            }else{
                baseCheckList.push(0)
            }
            if(that.data.basicInformation.hosLevel){
                baseCheckList.push(1)
            }else{
                baseCheckList.push(0)
            }
            if(that.data.basicInformation.optType){
                baseCheckList.push(1)
            }else{
                baseCheckList.push(0)
            }
            if(that.data.basicInformation.hosType){
                baseCheckList.push(1)
            }else{
                baseCheckList.push(0)
            }
        }
        if(baseCheckList.indexOf(0)!=-1){
            that.openPrompt('基础信息') 
        }
        //校验友商信息
        let FriendlyCheckList=[]
        if(!that.data.friendlyCollect||!that.data.hasFriendLyInfo){
            that.setData({
                friendlyInfo:[{ deviceList: [],
                contactList: [],
                hasFriendlyAgent: 0}]
            })
        }else{
            that.data.friendlyInfo.forEach(item=>{
                console.log(item.friendlyBusiness)
                if(item.friendlyBusiness){
                    FriendlyCheckList.push(1) 
                }else{
                    FriendlyCheckList.push(0)
                }
                item.deviceList.forEach(itm=>{
                    if(itm.deviceName){
                        FriendlyCheckList.push(1)
                    }else{
                        FriendlyCheckList.push(0)
                    }
                    if(itm.deviceCount){
                        FriendlyCheckList.push(1) 
                    }else{
                        FriendlyCheckList.push(0)
                    }
                })
                if(!item.hasFriendlyAgent){
                    item.friendlyAgentName=''
                    item.contactList=[]
                }else{
                    if(item.friendlyAgentName){
                        FriendlyCheckList.push(1) 
                    }else{
                        FriendlyCheckList.push(0)
                    }
                }
                item.remark=item.remark?item.remark:''
                item.images=item.images?item.images.toString():''
            })
        }
        if(FriendlyCheckList.indexOf(0)!=-1){
            that.openPrompt('友商信息')
        }
        //校验医院部门信息
        let hospitalCheckList=[]
        if(!that.data.deptCollect){
            that.data.departmentInfo=[{contactList: []}]
        }else{
            that.data.departmentInfo.forEach(item=>{
                if(item.name){
                    hospitalCheckList.push(1)
                }else{
                    hospitalCheckList.push(0)
                }
                if(item.contactList?.length==0||!item.contactList){
                    hospitalCheckList.push(0)
                }else{
                    hospitalCheckList.push(1)
                }
                item.remark=item.remark?item.remark:''
                item.images=item.images?item.images.toString():''
            })
        }
        if(hospitalCheckList.indexOf(0)!=-1){
            that.openPrompt('部门信息')
        }
        //公司信息校验
        let companyCheckList=[]
        that.data.companyInfo.forEach(item=>{
            if(!item.isCollect){
                item.companyList=[]
            }else{
                item.companyList.forEach(itm=>{
                    if(itm.companyType){
                        companyCheckList.push(1)
                    }else{
                        companyCheckList.push(0)
                    }
                    if(itm.companyName){
                        companyCheckList.push(1)
                    }else{
                        companyCheckList.push(0)
                    }
                    if(itm.contactList?.length==0||!itm.contactList){
                        companyCheckList.push(0)
                    }else{
                        companyCheckList.push(1)
                    }
                    itm.remark=itm.remark?itm.remark:''
                    itm.images=itm.images?itm.images.toString():''
                })
            }
        })
        if(companyCheckList.indexOf(0)!=-1){
            that.openPrompt('公司信息')
        }
        if(baseCheckList.indexOf(0)==-1&&FriendlyCheckList.indexOf(0)==-1&&hospitalCheckList.indexOf(0)==-1&&companyCheckList.indexOf(0)==-1){
            let obj={taskId:that.data.taskId,hospitalId:that.data.hospitalId,mechanismUpdate:that.data.mechanismUpdate,...that.data.basicInformation,friendlyCollect:that.data.friendlyCollect,hasFriendLyInfo:that.data.hasFriendLyInfo,friendlyInfo:that.data.friendlyInfo,deptCollect:that.data.deptCollect,departmentInfo:that.data.departmentInfo,companyInfo:that.data.companyInfo}
            console.log('提交成功',obj)
            
            lbbTaskService.collectHospital({mechanismInfo:JSON.stringify(obj)},function (res) {
                if (that.data.activeKey == 3) {
                    wx.navigateBack({
                        delta: 1
                    })
                } else {
                    operateMethod(that.data.operationlist, that.data.taskId, that.data.hospitalId, that.data.taskType, that.data.operationTypeCode)
                }
            })
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },
    //校验提示
    openPrompt(rext) {
        wx.showToast({
            title: `请检查${rext?rext:''}必填项`,
            icon: 'error',
            duration: 2000
        })
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})